package com.webex.ta.hydra.clipboard;

import com.webex.ta.hydra.core.Command;

import java.util.Vector;
import java.util.List;
import java.util.ArrayList;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-7
 * Time: 9:02:09
 */
public class ClipBoard {
    private static ClipBoard instance;

    private Vector<Command> contents = new Vector<Command>();

    private List<List<String>> cellValues = new ArrayList<List<String>>();

    private ClipBoard() {}

    private boolean isRendered = false;

    public static ClipBoard getInstance() {
        if (instance == null)
            instance = new ClipBoard();
        return instance;
    }

    public void setContents(Vector<Command> commands) {
        contents.clear();
        if (commands != null) {
            for (Command cmd : commands) {
                cmd.setCopied(true);
                contents.add(cmd.clone());
            }
        }
    }

    public boolean hasContent() {
        return !contents.isEmpty();
    }

    private void clearContents() {
        if (!contents.isEmpty()) {
            for (Command cmd : contents) {
                cmd.setCopied(false);
            }
            contents.clear();
        }
    }

    public void setContents(Command commands[]) {
		clearContents();
        if (commands != null) {
            for (Command cmd : commands) {
                contents.add(cmd);
                cmd.setCopied(true);
            }
            setRendered(false);
        }
	}

    public Vector<Command> getContents() {
        Vector<Command> result = new Vector<Command>();
        for (Command cmd : contents) {
            result.add(cmd.clone());
        }
        return result;
    }

    public boolean isRendered() {
        return isRendered;
    }

    public void setRendered(boolean rendered) {
        isRendered = rendered;
    }

    public void setCellValues(List<List<String>> cellValues) {
        this.cellValues = cellValues;
    }

    public List<List<String>> getCellValues() {
        return cellValues;
    }
}
